package com.ruoyi.evalution.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.evalution.domain.LabEvalution;
import com.ruoyi.evalution.dto.UserScoreDto;
import com.ruoyi.evalution.service.ILabEvalutionService;
import com.ruoyi.evalution.service.ILabEvalutionTargetService;
import com.ruoyi.system.domain.ReceiptForm;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 实验室评测Controller
 * 
 * @author winner pan
 * @date 2022-04-15
 */
@RestController
@RequestMapping("/evalution/labEvalution")
public class LabEvalutionController extends BaseController {
	@Autowired
	private ILabEvalutionService labEvalutionService;
	@Autowired
	private ILabEvalutionTargetService labEvalutionTargetService;
	/**
	 * 查询实验室评测列表
	 */
	@PreAuthorize("@ss.hasPermi('evalution:labEvalution:query')")
	@GetMapping("/list")
	public TableDataInfo list(LabEvalution labEvalution) {
		startPage();
		List<LabEvalution> list = labEvalutionService.selectLabEvalutionList(labEvalution);
		return getDataTable(list);
	}

	/**
	 * 导出实验室评测列表
	 */
	//@PreAuthorize("@ss.hasPermi('evalution:labEvalution:export')")
	@Log(title = "实验室评测", businessType = BusinessType.EXPORT)
	@GetMapping("/export")
	public AjaxResult export(Long instanceId) {
		List<UserScoreDto> list = labEvalutionTargetService.exportLabEvalutionTargetList(instanceId);
		ExcelUtil<UserScoreDto> util = new ExcelUtil<UserScoreDto>(UserScoreDto.class);
		return util.exportExcel(list, "labEvalution");
	}

	/**
	 * 获取实验室评测详细信息
	 */
	@PreAuthorize("@ss.hasPermi('evalution:labEvalution:query')")
	@GetMapping(value = "/{evalutionId}")
	public AjaxResult getInfo(@PathVariable("evalutionId") Long evalutionId) {
		return AjaxResult.success(labEvalutionService.selectLabEvalutionById(evalutionId));
	}

	/**
	 * 新增实验室评测
	 */
	@PreAuthorize("@ss.hasPermi('evalution:labEvalution:edit')")
	@Log(title = "实验室评测", businessType = BusinessType.INSERT)
	@PostMapping
	public AjaxResult add(@RequestBody LabEvalution labEvalution) {
		labEvalutionService.insertLabEvalution(labEvalution);
		return AjaxResult.success(labEvalution);
	}

	/**
	 * 修改实验室评测
	 */
	@PreAuthorize("@ss.hasPermi('evalution:labEvalution:edit')")
	@Log(title = "实验室评测", businessType = BusinessType.UPDATE)
	@PutMapping
	public AjaxResult edit(@RequestBody LabEvalution labEvalution) {
		labEvalutionService.updateLabEvalution(labEvalution);
		return AjaxResult.success(labEvalution);
	}
	@PreAuthorize("@ss.hasPermi('evalution:labEvalution:edit')")
	@Log(title = "提交料单流程", businessType = BusinessType.UPDATE)
	@PostMapping("/commit")
	public AjaxResult commit(@RequestBody LabEvalution labEvalution) {
		 return AjaxResult.success( labEvalutionService.commitLabEvalution(labEvalution));
	}

	/**
	 * 删除实验室评测
	 */
	@PreAuthorize("@ss.hasPermi('evalution:labEvalution:edit')")
	@Log(title = "实验室评测", businessType = BusinessType.DELETE)
	@DeleteMapping("/{evalutionId}")
	public AjaxResult remove(@PathVariable Long evalutionId) {
		return toAjax(labEvalutionService.deleteLabEvalutionById(evalutionId));
	}
}
